package main

import (
	"github.com/micro/go-micro/client"
	"github.com/micro/go-micro/cmd"
	"github.com/micro/go-micro/metadata"
	"golang.org/x/net/context"
	log "qiniupkg.com/x/log.v7"

	"time"
	proto "wangkechun/micro-test2/hello_server/proto/example"
)

func main() {
	// call()
	cmd.Init()

	pub()
	time.Sleep(time.Second)
}

// publishes a message
func pub() {
	msg := client.NewPublication("topic.go.micro.srv.hello", &proto.Message{
		Say: "This is a publication",
	})

	ctx := metadata.NewContext(context.Background(), map[string]string{
		"X-User-Id": "john",
		"X-From-Id": "script",
	})

	// publish message
	if err := client.Publish(ctx, msg); err != nil {
		log.Error("pub err: ", err)
		return
	}

	log.Infof("Published: %v\n", msg)
}
